package com.wang.vagus.base;

import com.wang.vagus.exception.BaseException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result {
    private int code;
    private String message;
    private Object data;

    public static Result success(Object data) {
        return Result.builder()
                .code(ResultEnum.SUCCESS.getCode())
                .message(ResultEnum.SUCCESS.getMessage())
                .data(data)
                .build();
    }

    public static Result error(ResultEnum resultEnum) {
        return Result.builder()
                .code(resultEnum.getCode())
                .message(resultEnum.getMessage())
                .build();
    }

    public static Result error(BaseException baseException) {
        return Result.builder()
                .code(baseException.getCode())
                .message(baseException.getMessage())
                .build();
    }

    public static Result error(Exception exception) {
        return Result.builder()
                .code(500)
                .message(exception.getMessage())
                .build();
    }

}
